import Vuex from 'vuex';
import { emitter, clone } from '$'

export default new Vuex.Store({
  state: {
    paperInfo: {
      content: [],
      sortData: [],
      saveData: [],
    },
    title: '',
    moduleId: '',
    manageId: '',
  },
  mutations: {
    set_paper_title(state, payload) {
      state.title = clone(payload);
    },
    set_manage_id(state, payload) {
      state.manageId = clone(payload);
    },
    set_knowledge_moduleId(state, payload) {
      state.moduleId = clone(payload);
    },
    set_paper_content(state, payload) {
      emitter.emit('knowledge-element-change');
      emitter.emit('sort-change', payload)
      state.paperInfo.content = clone(payload);
    },
    set_paper_refresh(state, payload) {
      emitter.emit('refresh-change');
      state.paperInfo.content = clone(payload);
    },
    set_paper_init(state, payload) {
      state.paperInfo.content = clone(payload);
    },
    set_paper_save(state, payload) {
      state.paperInfo.saveData = clone(payload);
    },
    set_sort_data(state, payload) {
      state.paperInfo.sortData = clone(payload);
    },
  },
  getters: {
    content: state => state.paperInfo.content,
    title: state => state.title,
  } 
});
